package com.catmiao.rdd.operate.transform;

import com.google.common.collect.Lists;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

/**
 * @author ChengMiao
 * @title: Transfer_01_Map
 * @projectName spark_study
 * @description: TODO
 * @date 2024/11/25 16:27
 */
public class Transfer_01_Map {

    public static void main(String[] args) {

        final SparkConf conf = new SparkConf();
        conf.setAppName("appName");
        conf.setMaster("local[*]");

        final JavaSparkContext jsc = new JavaSparkContext(conf);
        JavaRDD<Integer> rdd = jsc.parallelize(
                Lists.newArrayList(1, 2, 3, 4),
                2);

        /**
         * map 对单值数据进行处理
         *
         *      - 默认情况下 新创建的rdd的分区刷领续与原rdd的分区一致
         */

        JavaRDD<Integer> rdd2 = rdd.map(x -> x * x);

        rdd2.collect().forEach(System.out::println);


        jsc.close();
    }
}
